$(function(){
    var tel = new Tel();
    $("#telNew").blur(function(){
        tel.telConfirmFun("#telOld","#telNew","#telMsg")
    })
    $("#telCode").click(function(){
        if(!tel.isRight){
            alert("请输入正确手机号")
        }else{
            //
            //
            //发送验证码
            //
            //
            if(tel.isCount){
                tel.isCount = false;
                tel.countDownFun("#telCode","telCodeNum")
            }

        }
    })
    $("#telSubmit").click(function(){
        if(tel.isRight && $("#telCodeIpt").val() != ""){
            //
            //
            //提交
            //
            //
            console.log("success")
        }
    })
})

var Tel = function(){
    this.isRight = true;
    this.isCount = true;
    //更改手机号验证
    this.telConfirmFun = function(telOldId,telNewId,telMsg){ //旧手机号id，新手机号id，信息提示区id
        if($(telNewId).val() == ""){
            $(telMsg).text("请输入手机号").show();
            this.isRight = false;
        }else if(!(/^1[34578]\d{9}$/.test($(telNewId).val()))){
            $(telMsg).text("输入手机号格式不正确").show();
            this.isRight = false;
        }else if($(telNewId).val() == $(telOldId).val()){
            $(telMsg).text("您输入的手机号与旧手机号相同，请重新输入").show();
            this.isRight = false;
        }else{
            $(telMsg).hide();
            this.isRight = true;
        }
    }
    //发送验证码计时器
    this.countDownFun = function(telCode,telCountNum){//发送验证码区域id，读秒区域id（自定义，无#）
        var _this = this;
        $(telCode).html("<span style='color:#ccc'><span id='" + telCountNum + "'>60</span>秒后可重新发送</span>")
        var countDownStart = window.setInterval(function(){
            $("#" + telCountNum + "").text($("#" + telCountNum + "").text() - 0 - 1);
            if($("#" + telCountNum + "").text()- 0 == 0){
                window.clearInterval(countDownStart)
                _this.isCount = true;
                $(telCode).html("发送验证码")
            }
        },1000)
    }
}